#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2.5e5+10;

typedef long long ll;

#define in read()
#define pb push_back

int n,m,stk[MAXN],top;
ll f[MAXN],d[MAXN];
int vis[MAXN],siz[MAXN],dfn[MAXN],tot,fa[22][MAXN],dep[MAXN],k;
int need[MAXN];

struct edge{
	int v;ll w;
};

bool cmp(int x,int y){return dfn[x] < dfn[y];}

vector<edge> G[MAXN];

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch=='-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1) + (x<<3) + (ch^48);
	return x*sgn;
}

void dfs(int x,int p){
	siz[x] = 1,fa[0][x] = p;dfn[x] = ++tot;dep[x] = dep[p] + 1;
	for(int i = 1;i <= 20;i++) fa[i][x] = fa[i-1][fa[i-1][x]];
	for(int i = 0;i < G[x].size();i++){
		int y = G[x][i].v;
		if(y == p) continue;
		if(x == 1) d[y] = G[x][i].w;
		else d[y] = min(d[x],G[x][i].w);
		dfs(y,x);
		siz[x] += siz[y];
	}
}

int lca(int x,int y){
	if(dep[x] < dep[y]) swap(x,y);
	for(int i = 20;i >= 0;i--)
		if(dep[fa[i][x]] >= dep[y]) x = fa[i][x];
	if(x == y) return x;
	for(int i = 20;i >= 0;i--){
		if(fa[i][x] != fa[i][y]){
			x = fa[i][x];
			y = fa[i][y];
		}
	}
	return fa[0][x];
}

ll dis(int x,int y){
	if(x == 1 || y == 1) return d[x+y-1];
	return min(d[x] , d[y]);
}

void link(int x,int y){
	G[x].pb(edge{y,dis(x,y)});
}

void build(){
	sort(need+1,need+k+1,cmp);
	stk[top = 1] = 1; G[1].clear();
	for(int i = 1;i <= k;i++){
		int x = need[i];
		if(x == 1) continue;
		int l = lca(stk[top],x);
		if(l != stk[top]){
			while(dfn[l] < dfn[stk[top-1]]){
				link(stk[top-1],stk[top]);
				top--;
			}
			if(dfn[l] > dfn[stk[top-1]]){
				G[l].clear();
				link(l,stk[top]);
				stk[top] = l;
			}else{
				link(l,stk[top--]);
			}
		}
		G[x].clear(); stk[++top] = x;
	}
	for(int i = 1;i < top;i++) link(stk[i],stk[i+1]);
}	

void dp(int x,int p){
	f[x] = 0;
	for(int i = 0;i < G[x].size();i++){
		int y = G[x][i].v,w = G[x][i].w;
		dp(y,x);
		if(vis[y] == m) f[x] = f[x] + w;
		else f[x] = f[x] + min(f[y],(ll)w);
	}
}

int main (){
	n = in;
	for(int i = 1;i < n;i++){
		int u = in,v = in,w = in;
		G[u].pb(edge{v,w});
		G[v].pb(edge{u,w});
	}
	dfs(1,0);
	m = in;
	while(m--){
		k = in;
		for(int i = 1;i <= k;i++) need[i] = in,vis[need[i]] = m;
		build();
		dp(1,0);
		printf("%lld\n",f[1]);
	}
	return 0;
}
